import axios from '.'

const instance = axios.create()

/**
 * 地区疫情信息
 */
export interface IEpidemicInfo {
    today: IEpidemicInfoToday
    total: IEpidemicInfoTotal
    extData: IEpidemicInfoExtData
    /**
     * 地名
     */
    name: string
    id: string
    lastUpdateTime: string
    children: IEpidemicInfo[]
}

/**
 * 当天疫情信息
 */
export interface IEpidemicInfoToday {
    /**
     * 确诊
     */
    confirm: number
    /**
     * 疑似
     */
    suspect: number
    /**
     * 治愈
     */
    heal: number
    /**
     * 死亡
     */
    dead: number
    /**
     * 严重?
     */
    severe: number
    /**
     * 累计确诊新增
     */
    storeConfirm: number
}

/**
 * 疫情总数
 */
export interface IEpidemicInfoTotal {
    /**
     * 累计确诊
     */
    confirm: number
    suspect: number
    heal: number
    dead: number
    severe: number
    input: number
}

/**
 * 疫情额外数据
 */
export interface IEpidemicInfoExtData {
    /**
     * 无症状
     */
    noSymptom: number
    /**
     * 新增无症状
     */
    incrNoSymptom: number
}

/**
 * 获取疫情信息的响应接口
 */
export interface IEpidemicResponse {
    reqId: number
    code: number
    msg: string
    data: {
        chinaTotal: {
            today: IEpidemicInfoToday & {
                /**
                 * 境外输入新增
                 */
                input: number
            }
            total: IEpidemicInfoTotal
            extData: IEpidemicInfoExtData
        }
        chinaDayList: {
            date: '2022-11-19'
            today: {
                confirm: number
                suspect: number
                heal: number
                dead: number
                severe: number
                storeConfirm: number
                input: number
            }
            total: {
                confirm: number
                suspect: number
                heal: number
                dead: number
                severe: number
                input: number
                storeConfirm: number
            }
            extData: null
            lastUpdateTime: null
        }[]
        lastUpdateTime: string
        overseaLastUpdateTime: string
        areaTree: IEpidemicInfo[]
    }
    timestamp: number
}

/**
 * 请求疫情数据
 */
export function getEpidemicData() {
    return instance.get<IEpidemicResponse>('https://c.m.163.com/ug/api/wuhan/app/data/list-total')
}
